package com.icarbonx.dap.notification.msgservice.redis

import redis.clients.jedis.{Jedis, Protocol}


/**
 * RedisEndpoint represents a redis connection endpoint info: host, port, auth password
 * db number, and timeout
 *
 * @param host the redis host or ip
 * @param port the redis port
 */
case class RedisEndpoint(val host: String = Protocol.DEFAULT_HOST,
                         val port: Int = Protocol.DEFAULT_PORT,
                         val password: String = null,
                         val timeout: Int = Protocol.DEFAULT_TIMEOUT)
  extends Serializable {
  /**
   * Connect tries to open a connection to the redis endpoint,
   * optionally authenticating and selecting a db
   *
   * @return a new Jedis instance
   */
  def connect(): Jedis = {
    ConnectionPool.connect(this)
  }

  def returnResource(jedis: Jedis) = {
    ConnectionPool.returnResource(this, jedis)
  }

  def close() = {
    ConnectionPool.close(this)
  }
}




